package miniMVC.patterns
{
	import flash.events.Event;
	
	import miniMVC.i.IFacade;
	import miniMVC.i.ISender;

	/**
	 * 消息发送者
	 * 绑定对象到facace后发消息
	 * @author Pelephone
	 * @website http://cnblogs.com/pelephone
	 */
	public class Sender implements ISender
	{
		// 引用facade单例工厂
		protected var facade:IFacade;
		
		public function Sender()
		{
			onConstructInject();
		}
		
		/**
		 * 构造时配置注入相关信息
		 */
		protected function onConstructInject():void
		{
			facade = Facade.getInstance();
		}
		
		/**
		 * 发消息让facade拖管
		 * 不调用facade的sendNote方法是为了让监听的对象能获取target,即发消息的源
		 * @param type
		 * @param obj
		 * @param cancelable
		 */
		public function sendNote(type:String, obj:Object=null, cancelable:Boolean=false):void
		{
			facade.dispatchEvent(new Note(type,obj,false,cancelable));
		}
		
		public function dispatchNote(event:Event):Boolean
		{
			return facade.dispatchEvent(event);
		}
	}
}